<template>
  <!-- 法律法规 -->
  <view class="lawsAndRegulations">
    <view class="wrapper-content">
      <scroll-view
        scroll-y="true"
        @scrolltolower="scrollBottom"
        :style="[
          {
            height: !loading && !noMore ? '95vh' : '100%',
          },
        ]"
        v-if="dataSource.length"
      >
        <view
          class="wrapper-item"
          v-for="(v, i) in dataSource"
          :key="i"
          :data-url="`/guideInfo/lawsAndRegulations/regulationsCatalogue?id=${v.id}&title=${v.regulationsName}`"
          @click="handleClickRouter"
        >
          <view class="lt"
            ><image
              :src="
                v.regulationsImageDesc
                  ? imgPrefix + v.regulationsImageDesc
                  : baseImgUrl + 'regulations.png'
              "
              mode=""
            ></image
          ></view>
          <view class="rt">
            <view class="name"> 《{{ v.regulationsName }}》 </view>
            <view class="clause"> 法律条文：{{ v.numberOfArticles }}条 </view>
            <view class="clause"> 发布时间：{{ v.createTime }} </view>
          </view>
        </view>
        <view class="pageBottom" v-if="pageBottom">—— 到底了 ——</view>
      </scroll-view>

      <view v-if="!dataSource.length">
        <u-empty
          mode="list"
          text="暂无内容！"
          :icon="baseImgUrl + 'no-icon2.png'"
        >
        </u-empty>
      </view>
    </view>
  </view>
</template>

<script>
import { messageList } from "@/api/messages.js";
import mixin from "@/utils/mixin.js";
import { handleClickRouter } from "@/utils/util.js";

export default {
  mixins: [mixin],
  data() {
    return {
      baseImgUrl: this.$baseImgUrl,
      imgPrefix: uni.getStorageSync("imgPrefix"),
      dataSource: [],
      pageBottom: false,
      pageConfig: {
        pageNo: 1,
        pageSize: 10,
        total: 0,
      },
    };
  },
  onShow() {
    this.dataSource = [];
    this.pageConfig.pageNo = 1;
    this.getList();
  },
  methods: {
    handleClickRouter,
    scrollBottom() {
      let current = (this.pageConfig.pageNo += 1);
      let pages = Math.ceil(this.pageConfig.total / this.pageConfig.pageSize);
      if (current <= pages) {
        this.getList();
      } else {
        this.pageBottom = true;
      }
    },
    getList() {
      let data = {
        noticeType: 6,
        pageNo: this.pageConfig.pageNo,
        pageSize: this.pageConfig.pageSize,
      };

      messageList(data).then((res) => {
        this.dataSource = this.dataSource.concat(res.result.records || []);
        this.pageConfig.total = res.result.total;
      });
    },
  },
};
</script>

<style lang="scss">
.lawsAndRegulations {
  height: 100%;
  .wrapper-content {
    background: #f9f9f9;
    height: 100%;
    padding: 24rpx 20rpx;
    .wrapper-item {
      padding: 30rpx;
      background: #ffffff;
      margin-bottom: 1vh;
      display: flex;
      .lt {
        width: 133rpx;
        height: 166rpx;
        margin-right: 30rpx;
        image {
          width: 133rpx;
          height: 166rpx;
        }
      }
      .rt {
        .name {
          font-size: 32rpx;
          font-family: PingFang SC;
          font-weight: bold;
          margin-bottom: 17rpx;
          margin-top: 20rpx;
        }

        .clause {
          margin-bottom: 17rpx;
          font-size: 26rpx;
          font-family: PingFang SC;
          font-weight: 400;
          color: #a1a1a1;
        }
      }
    }
  }
}
</style>
